<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>数组扁平化</title>
</head>
<body>
	<script>

    const arr = [1,2,[3, [4,[5]]], [6,[7]]]
    function flatten1(array) {
      while (array.some((item) => Array.isArray(item))) {
        // array = array.flat()
        array = [].concat(...array)
      }
      return array;
    }

    function flatten2(arr) {  
    return arr.reduce((result, item)=> {
        return result.concat(Array.isArray(item) ? flatten(item) : item);
        }, []);
    }
    function flatten3(arr) {
		    var res = [];
		    arr.forEach(item => {
		        if(Array.isArray(item)) {
		            res = res.concat(flatten(item));
		        } else {
		            res.push(item);
		        }
		    });
		    return res;
		}

    console.log(132123, flatten1(arr))
    </script>
</body>
</html>